import axios from 'axios';
import store from '../store/Index';

const service = axios.create({
    // process.env.NODE_ENV === 'development' 来判断是否开发环境
    // easy-mock服务挂了，暂时不使用了
    // baseURL: 'https://www.easy-mock.com/mock/592501a391470c0ac1fab128',




    //baseURL: 'http://localhost:5102',//接口的基地址
    baseURL: process.env.NODE_ENV === 'development' ? 'http://localhost:5102' : 'http://47.110.92.230:8087',//接口的基地址


    timeout: 5000 * 1000       //调用接口的超时时间
});

//请求拦截器
service.interceptors.request.use(
    config => {
        if (store.state.token) {
            config.headers['Authorization'] = 'Bearer ' + store.state.token
        }
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);
//响应拦截器
service.interceptors.response.use(
    response => {
        if (response.status === 200) {
            //console.log("111")
            //请求
            return response.data;
        } else {
            Promise.reject();
        }
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

export default service;